
package bbchess.dialogs;

/**
 * History Dialog displays move history.
 * @author Tyler Eastman
 */
public class HistoryDialog extends ChessDialog {

    private int lineContents;

    /** Creates new form HistoryDialog */
    public HistoryDialog(java.awt.Frame parent, boolean modal) {
        super(parent, modal, false);
        lineContents = 1;
        this.setTitle("History");
        initComponents();
        this.setLocationRelativeTo(null);
    }

    public void appendText(String text) {
        historyText.append(text);

        if (lineContents == 1) {
            lineContents++;
        }

        else {
            historyText.append("\n");
            lineContents = 1;
        }
    }

    public void clearHistory() {
        historyText.selectAll();
        historyText.replaceSelection("");
        repaint();
    }

    @Override
    public void dispose() {
        super.dispose();
        super.getMainGui().setHistoryMenuItemSelected(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        historyText = new javax.swing.JTextArea();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jScrollPane1.setAutoscrolls(true);
        jScrollPane1.setHorizontalScrollBar(null);

        historyText.setColumns(20);
        historyText.setEditable(false);
        historyText.setRows(5);
        jScrollPane1.setViewportView(historyText);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextArea historyText;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
